const Appliaction = require('ee-core').Appliaction;
const { app, Menu } = require('electron');
function createMenu() {
  const template = [
    {
      label: '文件' || app.name,
      submenu: [
        { label: '关闭', role: 'close' },
        { label: '退出', role: 'quit', accelerator: 'ctrl+q' },
      ],
    },
    {
      label: '编辑',
      submenu: [
        { label: '撤销', role: 'undo' },
        { label: '重做', role: 'redo' },
        { label: '剪切', role: 'cut' },
        { label: '复制', role: 'copy' },
        { label: '粘贴', role: 'paste' },
        { label: '开发者工具', role: 'toggleDevTools', accelerator: 'ctrl+shift+i' },
      ],
    },
  ];

  const menu = Menu.buildFromTemplate(template);
  Menu.setApplicationMenu(menu);
}

class Main extends Appliaction {
  constructor() {
    super();
    // this === eeApp;
  }

  /**
   * core app have been loaded
   */
  async ready() {
    // do some things
  }

  /**
   * electron app ready
   */
  async electronAppReady() {
    // do some things
  }

  /**
   * main window have been loaded
   */
  async windowReady() {
    createMenu();
    // do some things
    // 延迟加载，无白屏
    const winOpt = this.config.windowsOption;
    if (winOpt.show == false) {
      const win = this.electron.mainWindow;
      win.once('ready-to-show', () => {
        win.show();
      });
    }
  }

  /**
   * before app close
   */
  async beforeClose() {
    // do some things
  }
}

new Main();
